#!/bin/ksh
case $# in
    0) print "Usage: $0 [-2] <Pascal-File>  [ {function-name}+ | "_main" ] ";
       print "	One or more top-level-functions or _main (unnamed main program)";
       exit 1;;
   *) case $1 in
	-2) YAP_VERSION=2; shift; FILE=$1; shift ;;
	*)  YAP_VERSION=3; FILE=$1; shift ;;
      esac
esac

NAME=${FILE%.p.*}
NAME=${NAME%.adt.*}
BIN=`dirname $0`
AWK='awk'
TR='tr'

tr 'A-Z' 'a-z' < $FILE | sed -f "$BIN"/tokenize_PASCAL.sed | $AWK -f "$BIN"/tokenize_PASCAL.skip.awk  | tr -c 'a-zA-Z0-9_=<>:' '\012' | $AWK -f "$BIN"/tokenize_PASCAL.procs.awk | sed -f "$BIN"/tokenize_PASCAL.synonyms | "$BIN"/PascalExpand $* | $AWK -f $BIN/tokenize_PASCAL.awk version="$YAP_VERSION" > oo
case $YAP_VERSION in
    2)  mv oo $NAME.tokens;;
    3)  cat oo | wc -l > $NAME.tokens;
        cat oo >> $NAME.tokens;
        rm oo;;
esac

chmod g+rw $NAME.tokens
